/**
 * Created by Administrator on 2016/12/15.
 */
//隐藏条件和显示条件
function myhide(){
	if($(".myhide a").text()=="隐藏条件"){
		$(".condition").css("display","none");
		$(".myhide a").text("显示条件");
		$(".myhide i").removeClass("icon icon-caret-down");
		$(".myhide i").addClass("icon icon-caret-up");
	}
	else{
		$(".condition").css("display","block");
		$(".myhide a").text("隐藏条件");
		$(".myhide i").removeClass("icon icon-caret-up");
		$(".myhide i").addClass("icon icon-caret-down") ;
	}
}

$(function() {
	/*初始化*/
	init();
});

function init() {
	$("#workTable").bootstrapTable({
		method:"post",
		url:"http://192.168.59.3:8082/console/projectcapital/getProjectCapital",
		contentType:"application/json",
		onLoadSuccess:function (data) {
			console.log(data);
        },
        onClickRow: function(row,value) {
            console.log(row);
            var str = "";
            for(var key in row) {
                str += "&" + key + "=" + row[key];
            }
            layer.open({
                type: 2,
                maxmin: true,
                shadeClose: true,
                area: ['100%', '100%'],
                content: `management/management.html?${str.slice(1)}`
            });



        },
        responseHandler: function (res) {
            console.log(res);
            return {rows: res.data.list, total: res.data.total};
        }
	});

    // $.ajax({
    //     type:"post",
    //     data:JSON.stringify({"pageNum":'1',"pageSize":10,"projectCode":1}),
    //     contentType:"application/json",
    //     url:"http://192.168.59.3:8082/console/projectcapital/getProjectCapital",
    //     success:function  (data) {
    //         console.log(data);
    //         data1 = JSON.parse(data).data.list;
    //         $('#workTable').bootstrapTable({
    //             method: 'post', //发送方式
    //             url: 'http://192.168.59.3:8082/console/projectcapital/getProjectCapital', // 接口路径 其他工人&明细数据为空
    //             onClickRow: function(row,value) {
    //             	console.log(row);
    //                 var str = "";
    //                 for(var key in row) {
    //                     str += "&" + key + "=" + row[key];
    //                 }
    //                 layer.open({
    //                     type: 2,
    //                     maxmin: true,
    //                     shadeClose: true,
    //                     area: ['100%', '100%'],
    //                     content: `management/management.html?${str.slice(1)}`
    //                 });
    //
    //
    //
    //             },
    //             onLoadSuccess: function(){
    //
    //                 var
    //                     oTrs = $('tbody tr'),
    //                     len = oTrs.length;
    //
    //                 for(var i = 0; i < len - 1; i++) {
    //                     //console.log(oTrs[i].lastChild);
    //                     oTrs[i].lastChild
    //                 }
    //                 //console.log(this);
    //             }
    //         });
    //
    //
    //
    //     },
    //     error:function  (err) {
    //         console.log(err.responseText)
    //     }
    // });






	//  清空条件选择
	$("#clearoption").click(function() {

		for(var i = 0; i < $(".order-num>input").length - 2; i++) {

			$(".order-num>input").eq(i).val("");

		}
		$("#workTable").bootstrapTable("refresh","http://192.168.59.3:8082/console/projectcapital/getProjectCapital");

	});
	var oCode;
	var oNumVal;
	var oNameVal;
	var   oIdVal;
	var oCompany;
	var oData;
	//  搜索条件的 选择
	$("#searchOption").click(function() {
    oCode = $(".order-num>input").eq(3).val();
	oNumVal =$(".order-num>input").eq(0).val();
    oNameVal = $(".order-num>input").eq(1).val();
    oIdVal = $(".order-num>input").eq(2).val();
    oCompany = $(".order-num>input").eq(4).val();
    oDemoCode =$(".order-num>input").eq(5).val();
    
    

		$.ajax({
			type: "post",
			url: "http://192.168.59.3:8082/console/projectcapital/getProjectCapital",
			dataType : 'json',
			data: JSON.stringify({
		         "projectCode": oNumVal,
		         "projectName": oNameVal,
		         "constructUnit": oIdVal,
		         "constructionUnit": oCode,
		         "managerUserCode":oCompany,
		         "contractorName": oDemoCode
		        
		    }),
			contentType:"application/json",
			success: function(data) {
				
			console.log(data);
				
			data1 = responseHandler(data);
			
            $("#workTable").bootstrapTable('load',data1);
},
			error:function(err){
				console.log(err.responseText)
			}
		});
     
           
       

	});

}

function responseHandler(res) {
	console.log(res);
	var needData = {
		rows: res.data.list,
		total: res.data.total
	};
      return needData;
}

function indexFmt(val, row, index) {
	return index + 1;
}
function workTableQuery(params) {
	params["pageNum"] = (params.offset / params.limit) + 1;
	params.pageSize = params.limit;
	params.projectCode=1;
	return params;
}